<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\Showorder */
/* @var $showpic app\models\Showpic */
/* @var $form yii\widgets\ActiveForm */
/* @var $uploadForm app\models\UploadForm */

$this->title = '创建机器人晒单';
$this->params['breadcrumbs'][] = ['label' => '晒单', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="banner-create">

    <h1><?= Html::encode($this->title) ?></h1>

    <div class="banner-form">

        <?php $form = ActiveForm::begin(); ?>

        <div class="form-group">
            <?=$form->field($model,'content')->textarea()?>
            <?= Html::submitButton(Yii::t('app', 'Create'), ['class' => 'btn btn-success']) ?>
        </div>

        <?php ActiveForm::end(); ?>
        <?php $formajax = ActiveForm::begin([
            'options'=>[
                'id'=>'to-img-ajax',
                'enctype' => 'multipart/form-data',
            ],
            'action'=>Url::to(['showpic/create']),
        ]);?>
        <div class="three124">
            <span class="glyphicon glyphicon-bishop" id="openFolder"></span>
            <?=Html::activeHiddenInput($showpic,'auction_id',['value'=>$showpic->auction_id])?>
            <?=Html::activeHiddenInput($showpic,'user_id',['value'=>$showpic->user_id])?>
            <?=Html::activeHiddenInput($showpic,'product_id',['value'=>$showpic->product_id])?>
            <?= $form->field($uploadForm,'file')->fileInput(['id'=>'theImg','style'=>'display:none'])?>
        </div>
        <?php ActiveForm::end();?>
    </div>

</div>
<?php $this->beginBlock('js')?>
<script>
    var three124 = $('.three124').html();
    $(document).on('click','#openFolder',function(){
        $('#theImg').click();
    });
    $(document).on('change','#theImg',function(){
        var formData = new FormData($("#to-img-ajax")[0]);
        $.ajax({url:'<?=Url::to(['showpic/create'])?>',type:'POST',data:formData,processData:false,contentType:false,dataType:'json',success:function(data){
            if(data.status == '1') {
                var str = '';
                var length=data.data.showpics.length;
                for(var i=0;i<data.data.showpics.length;i++){
                    str += '<img src="/uploads/'+data.data.showpics[i].url+'" width="50px" height="50px"/>';
                }
                str += three124;
                $('.three124').html(str);
            }else if(data.status=='0'){
                console.log(data);
            }
        }
        });
    });
    $('.hand-submit').click(function(){
        $('#to-comment').submit();
    });
</script>
<?php $this->endBlock()?>